package com.reform.controller.project;


import com.reform.pojo.project.ProjectRecord;
import com.reform.res.Result;
import com.reform.service.IProjectRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-11-02
 */
@Api(tags = "ProjectRecordController")
@RestController
@RequestMapping("/project-record")
public class ProjectRecordController {

    @Autowired
    IProjectRecordService projectRecordService;

    @ApiOperation(value = "新建项目状态更改记录", notes = "新建项目状态更改记录")
    @PostMapping("/addProject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectRecords", value = "项目记录JSON数组", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result addProject(String projectRecords) throws SQLException {
        return projectRecordService.addProject(projectRecords);
    }

    @ApiOperation(value = "删除项目状态更改记录", notes = "删除项目状态更改记录")
    @PostMapping("/deleteProject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchId", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deleteProject(String batchId) throws SQLException {
        return projectRecordService.deleteProject(batchId);
    }

    @ApiOperation(value = "批量删除项目状态更改记录", notes = "删除项目状态更改记录")
    @PostMapping("/deleteProjects")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchIdList", value = "批次idJSON数组", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deleteProjects(String batchIdList) throws SQLException {
        return projectRecordService.deleteProjects(batchIdList);
    }

    @ApiOperation(value = "查询所有项目状态更改记录", notes = "查询所有项目状态更改记录")
    @GetMapping("/getAllProject")
    public Result getAllProject() throws SQLException {
        return projectRecordService.getAllProject();
    }

    @ApiOperation(value = "根据批次id查询所有项目状态更改记录", notes = "根据批次id查询所有项目状态更改记录")
    @PostMapping("/getProjectByBatchId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchId", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getProjectByBatchId(String batchId) throws SQLException {
        return projectRecordService.getProjectByBatchId(batchId);
    }
}
